
package com.jf.cloud.multishop.controller.multishop;

import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.common.security.AuthUserContext;
import com.jf.cloud.multishop.dto.ShopBankCardDTO;
import com.jf.cloud.multishop.service.ShopBankCardService;
import com.jf.cloud.multishop.vo.ShopBankCardVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author zz
 * @Date 2021/4/29 10:11
 */
@RestController("multishopShopBankCardController")
@RequestMapping("/m/apply_shop/shop_bank_card")
@Tag(name = "multishop-店铺银行卡信息")
public class ShopBankCardController {
    private final Logger LOGGER = LoggerFactory.getLogger(ShopBankCardController.class);

    @Autowired
    private ShopBankCardService shopBankCardService;

    @PostMapping("/save_and_apply_shop")
    @Operation(summary = "批量保存店铺银行卡信息并提交店铺审核信息" , description = "批量保存店铺银行卡信息并提交店铺审核信息")
    public ServerResponseEntity<Void> saveAndApplyShop(@Valid @RequestBody List<ShopBankCardDTO> shopBankCardDTOList) {
        Long shopId = AuthUserContext.get().getTenantId();
        shopBankCardService.insertBatchAndSubmitApply(shopBankCardDTOList, shopId);
        return ServerResponseEntity.success();
    }

    @GetMapping
    @Operation(summary = "根据银行卡id获取银行卡信息" , description = "根据银行卡id获取银行卡信息")
    public ServerResponseEntity<ShopBankCardVO> getById(@ParameterObject @RequestParam("shopBankCardId") Long shopBankCardId) {
        Long shopId = AuthUserContext.get().getTenantId();
        ShopBankCardVO shopBankCardVO = shopBankCardService.getByShopBankCardIdAndShopId(shopBankCardId, shopId);
        return ServerResponseEntity.success(shopBankCardVO);
    }

    @GetMapping("/list_by_shopId")
    @Operation(summary = "获取店铺下的银行卡列表" , description = "获取店铺下的银行卡列表")
    public ServerResponseEntity<List<ShopBankCardVO>> listByShopId() {
        Long shopId = AuthUserContext.get().getTenantId();
        List<ShopBankCardVO> shopBankCardVOList = shopBankCardService.listByShopId(shopId);
        return ServerResponseEntity.success(shopBankCardVOList);
    }

    @PostMapping
    @Operation(summary = "添加单个银行卡信息" , description = "添加单个银行卡信息")
    public ServerResponseEntity<Void> insert(@RequestBody @Valid ShopBankCardDTO shopBankCardDTO) {
        Long shopId = AuthUserContext.get().getTenantId();
        shopBankCardService.insertByShopId(shopBankCardDTO, shopId);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "根据银行卡id删除银行卡信息" , description = "根据银行卡id删除银行卡信息")
    public ServerResponseEntity<Void> deleteById(@RequestParam(value = "shopBankCardId") Long shopBankCardId) {
        shopBankCardService.deleteByShopBankCardId(shopBankCardId, AuthUserContext.get().getTenantId());
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新银行卡信息" , description = "更新银行卡信息")
    public ServerResponseEntity<Void> update(@RequestBody @Valid ShopBankCardDTO shopBankCardDTO) {
        shopBankCardService.updateByShopId(shopBankCardDTO, AuthUserContext.get().getTenantId());
        return ServerResponseEntity.success();
    }

    @PutMapping("/set_primary")
    @Operation(summary = "设置为主账号" , description = "设置为主账号")
    public ServerResponseEntity<Void> setPrimary(@RequestParam(value = "shopBankCardId") Long shopBankCardId) {
        shopBankCardService.setPrimaryByShopId(shopBankCardId, AuthUserContext.get().getTenantId());
        return ServerResponseEntity.success();
    }

    @PutMapping("/set_not_primary")
    @Operation(summary = "取消主账号" , description = "取消主账号")
    public ServerResponseEntity<Void> setNotPrimary(@RequestParam(value = "shopBankCardId") Long shopBankCardId) {
        shopBankCardService.setNotPrimaryByShopId(shopBankCardId, AuthUserContext.get().getTenantId());
        return ServerResponseEntity.success();
    }
}
